-
Notifications
You must be signed in to change notification settings - Fork 939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added conditional checks for empty grid placement #2640
base: main
Are you sure you want to change the base?
Added conditional checks for empty grid placement #2640
Conversation
Performance benchmarks:
|
This is related to #2638 and #2642. I need to think about the best way forward to address this. Yes, we can add a bunch of if statements as done here. However, I am inclined to see this as an architectural problem. At the moment, we don't distinguish carefully between drawing the space (e.g., the grid structure), the drawing of properties of the space (i.e., property layer portrayal), and the drawing of agents within the space. These are effectively all collapsed into a single draw_space method. I am inclined to redesign the API and explicitly separate these three things slightly. If you pass the same axes (in the case of matplotlib), you can draw them on top of each other, but if you pass separate axes, you can also portray them more cleanly. Any thoughts on this are welcome, preferably in #2642. |
I think we should implement an class PropertyLayerPortrayal:
def __init__(self, layer_name, colormap=None, color=None, alpha=1.0, vmin=None, vmax=None):
self.layer_name = layer_name
self.colormap = colormap
self.color = color
# etc... And then we can separate the space drawing into three parts. Maybe something like this: class SpaceRenderer:
def draw_structure(self, space, ax=None, **kwargs):
...
def draw_properties(self, space, propertylayer_portrayal, ax=None, **kwargs):
...
def draw_agents(self, space, agent_portrayal, ax=None, **kwargs):
...
# Composite method(not the best name)
def draw_all(self, space, agent_portrayal=None, property_config=None, ax=None, **kwargs):
... But this design may feel complex for beginners while also breaking the current API. |
@Sahil-Chhoker I like the direction of thought: encapsulate the portrayal of agents, space, and propertylayers into their own class, have three dedicated draw functions for each of them, and an overarching one that calls each of them. I'll try to find time to hash this out a bit further in the coming days.
|
The space drawer idea you link to was heavily inspired by altair's API. I still like the idea, and I think it is worth exploring further. However, it is also a more radical departure from the current API. Having |
Summary
Added
if
checks to confirm existence of agents before trying to place them on the grid, which before resulted in a error, now just displays the empty grid.Bug / Issue
fixes #2638
Additional Notes
No changes made to the
draw_hex_grid
function since the required changes are included in #2609.